package com.algorithm.lzr.array;

import com.sun.tools.javac.util.Assert;

/**
 * @Title: RemoveDuplicates
 * @Package com.algorithm.lzr.array
 * @Author liu.zr 2019-07-16 17:10
 * @Description: <移除有序数组中重复的元素>
 */
public class RemoveDuplicates {

    public static void main(String[] args) {
        int[] array = new int[]{1, 1, 2, 3, 5, 5, 7, 8};
        Assert.check(removeDuplicates(array) == 6);
    }


    public static int removeDuplicates(int[] array) {
        if (array.length == 0) return 0;
        int index = 1;
        for (int i = 0; i < array.length; i++) {
            if (array[i] != array[index]) array[index++] = array[i];
        }
        return index;
    }

}
